package com.stgy.lease.web.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stgy.lease.common.exception.StgyException;
import com.stgy.lease.common.result.ResultCodeEnum;
import com.stgy.lease.model.domain.*;
import com.stgy.lease.web.api.mapper.*;
import com.stgy.lease.web.api.service.ApartmentInfoService;
import com.stgy.lease.web.api.service.GraphInfoService;
import com.stgy.lease.web.api.service.LabelInfoService;
import com.stgy.lease.web.api.vo.ApartmentDetailVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author lingx
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2024-08-28 11:00:28
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Autowired
    private GraphInfoService graphInfoService;

    @Autowired
    private LabelInfoMapper labelInfoMapper;

    @Autowired
    private FacilityInfoMapper facilityInfoMapper;

    @Autowired
    private RoomInfoMapper roomInfoMapper;

    //根据id获取公寓信息
    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();
        ApartmentInfo apartmentInfo = this.getById(id);
        BeanUtils.copyProperties(apartmentInfo, apartmentDetailVo);

        List<GraphInfo> graphInfos = graphInfoService.list(Wrappers.lambdaQuery(GraphInfo.class)
                .eq(GraphInfo::getItemId, id)
                .eq(GraphInfo::getItemType, 1));
        apartmentDetailVo.setGraphVoList(graphInfos);

        List<LabelInfo> labelInfos = labelInfoMapper.selectByApartmentId(id);
        apartmentDetailVo.setLabelInfoList(labelInfos);

        List<FacilityInfo> facilityInfos = facilityInfoMapper.selectByApartmentId(id);
        apartmentDetailVo.setFacilityInfoList(facilityInfos);

        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(id);
        apartmentDetailVo.setMinRent(minRent);

        return apartmentDetailVo;
    }
}




